package com.coda.service.impl;

import com.coda.Constant.StatusConstant;
import com.coda.common.PageResult;
import com.coda.context.BaseContext;
import com.coda.dto.PageDto;
import com.coda.entity.OutStore;
import com.coda.mapper.OutStoreMapper;
import com.coda.service.OutStoreService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class OutStoreServiceImpl implements OutStoreService {

    @Autowired
    private OutStoreMapper outStoreMapper;

    /**
     * 添加出库单
     * @param outStore
     */
    @Override
    public void addOutStore(OutStore outStore) {
        outStore.setIsOut(StatusConstant.USER_STATE_NOT_PASS);
        outStore.setCreateBy(BaseContext.getCurrentId());
        outStore.setCreateTime(LocalDateTime.now());
        outStoreMapper.addOutStore(outStore);
    }

    /**
     * 分页查询
     * @param pageDto
     * @param outStore
     * @return
     */
    @Override
    public PageResult getPage(PageDto pageDto, OutStore outStore) {
        //设置分页参数
        PageHelper.startPage(pageDto.getPageNum(),pageDto.getPageSize());
        Page<OutStore> page = outStoreMapper.Page(outStore);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 确定出库
     * @param outStore
     */
    @Override
    public void isOutStore(OutStore outStore) {
        outStoreMapper.isStore(outStore);
    }

}
